package emailserving.domain;

import javax.persistence.*;

@Entity
@Table(name = "es_contents")
public class Content extends AbstractModel {


    private static final Find<Long, Content> find = new Find<Long, Content>() {
    };


    @Column(name = "subject")
    private String subject;

    @Lob
    @Column(name = "text")
    private String text;

    @OneToOne
    @JoinColumn(name = "job_id")
    private Job job;

    public Content(String subject, String text) {
        this.subject = subject;
        this.text = text;
    }

    public Content(String subject, String text, Job job) {
        this.subject = subject;
        this.text = text;
        this.job = job;
    }

    public static Content getContentOf(long jobId) {
        return find.where().eq("job_id", jobId).findUnique();
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public Job getJob() {
        return job;
    }

    public void setJob(Job job) {
        this.job = job;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Content content = (Content) o;

        if (text != null ? !text.equals(content.text) : content.text != null) return false;
        return !(job != null ? !job.equals(content.job) : content.job != null);

    }

    @Override
    public int hashCode() {
        int result = text != null ? text.hashCode() : 0;
        result = 31 * result + (job != null ? job.hashCode() : 0);
        return result;
    }


}
